<?php

class SearchController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
    }

    public function resultAction()
    {
        // action body
        $request = $this->getRequest();

        // Common attributes
        $category = $request->getParam('category');
        $type_id = $request->getParam('type');
        $status_id = $request->getParam('status');
        $city = $request->getParam('city');
        
        $query = new Reale_Model_Estate_Search();
        
        $query->setCategory_id($category)
                ->setType_id($type_id)
                ->setCity($city);
                
        if($status_id != ""){
        	$query->setStatus_id($status_id);
        }
                
        $start = ($request->getParam('start')) ? $request->getParam('start') : 0;
        $paging = NULL;
        $page_no = ($start / 10) + 1;
        $this->view->assign("cur_page", $page_no);
        if ($page_no > 10) {
            $page_no = $page_no - 10;
        } else {
            $page_no = 0;
        }
        $result = $query->search();
        $this->view->assign('result',$result);
    	
    }
    
    public function fillcityAction()
    {
    	$request = $this->getRequest();
        $format = $request->getParam('format', 'json');
        
        $mapper = new Reale_Model_Estate_SearchMapper();
        $result = $mapper->getCities();
        
        switch (strtolower($format)) {
                case 'json':
                    $this->_helper->json($result);
                    return;
                case 'jsonp':
                    $callback = $request->getParam('callback');
                    echo $callback.'('.$this->_helper->json($result, false).')';
                    return;
        }
        
    }

}

